/**
 * 登录Action
 */
import staticType from '../config/domainMap';

export const LOGIN_ACTION = 'LOGIN_ACTION';

export function fetchLogin(username, password) {
    return (dispatch, getState) => {
        dispatch({
            type: LOGIN_ACTION,
            payload: {     //真实的payload传值
                username
            },
            fetchPayload: {  //fetch传值
                url: `${staticType.DOMAIN_MAP.crm}/login`,
                options: {
                    method: 'post',
                    body: JSON.stringify({
                        username,
                        password
                    }),
                    credentials: "same-origin"
                },
                loadingOptions: { //是否显示LOADING
                    show: true
                },
                condition: function(json) {   //判断成功状态条件,如不输入,默认请求成功就返回成功
                    return json.code === 0 ? true : false;
                }
            }
        })
    }
}
